/* @(#)GSLoginAction.java    
*
* Project: BUS
*
* Modify Information:
* =============================================================================
*   Author       Date       Description
*   ------------ ---------- ---------------------------------------------------
*   Simonyi Peng 2006-2-7    建立
*
* Copyright Notice:
* =============================================================================
*    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
*        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
*        Haidian District, Beijing ,100081, China All rights reserved.
*
*    This software is the confidential and proprietary information of
*        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
*        You shall not disclose such Confidential Information and shall use it
*        only in accordance with the terms of the license agreement you entered
*        into with HiTRUST.
*
* Warning:
* =============================================================================
* 
*/
package com.hitrust.gs.action;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.commons.beanutils.BeanUtils;

import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.dao.GSOrderDeptInfoDAO;
import com.hitrust.gs.form.GSPayReceiveAlertQueryForm;
import com.hitrust.gs.form.GSPayReceiveStatusQueryForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.util.exception.*;
import com.hitrust.gs.util.lang.StringUtils;
import com.hitrust.gs.util.page.ResultProcess;
import com.hitrust.gs.vo.GSManufactureVO;
import com.hitrust.gs.vo.GSPayReceiveAlertQueryVO;
import com.hitrust.gs.vo.GSPayReceiveStatusQueryVO;
import com.hitrust.gs.business.GSBusOrgProcessor;
import com.hitrust.gs.business.GSManufactureProcessor;
import com.hitrust.gs.business.GSPayReceiveProcessor;


public class GSPayReceiveStatusQueryAction extends GSBaseAction {
	public String execute(GSBaseForm aForm) throws GSException {
	    
	    GSOperatorBean operatorBean = (GSOperatorBean)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        GSPayReceiveProcessor proc = new GSPayReceiveProcessor();
	        
	    String[] buffer = null;

	    GSPayReceiveStatusQueryForm tForm = (GSPayReceiveStatusQueryForm)aForm;
	    GSPayReceiveStatusQueryVO oaqVO = new GSPayReceiveStatusQueryVO();

        try{

		    oaqVO.deptid = tForm.deptid;
		    oaqVO.paytype = tForm.paytype;
		    oaqVO.provname = tForm.provname;
		    oaqVO.workcorpcategory = tForm.workcorpcategory;
		    oaqVO.payreceivedatestart = tForm.payreceivedatestart;
		    oaqVO.payreceivedateend = tForm.payreceivedateend;
		    
		    if(aForm.getRequest().getAttribute("ISQUERYCONDITIONEXIST")!=null){
		        //是执行完返回的，读出查询条件
		        oaqVO = (GSPayReceiveStatusQueryVO)aForm.getSession().getAttribute("QUERYCONDITION");
		    }
		    else{
			    //初次查询，缓存查询条件
			    aForm.getSession().setAttribute("QUERYCONDITION",oaqVO);
		    }

		    String[] tStr = this.getPageParams(aForm,operatorBean,oaqVO);
		    ArrayList statusList = proc.getPayReceiveStatusList(operatorBean,oaqVO,Integer.parseInt(tStr[0]),Integer.parseInt(tStr[1]));
			//放入ResultProcess对象为页面分页做准备
			ResultProcess tProc = new ResultProcess();
			tProc.setResult(statusList);
			aForm.getRequest().setAttribute("statuslist",tProc);
			//存储分页参数
			aForm.getRequest().setAttribute("pageSize",tStr[1]);
			aForm.getRequest().setAttribute("totalRecords",tStr[2]);
            
        }catch(Exception ex){
	        GSLogWriter.error(this,ex.toString());
	        tForm.getRequest().setAttribute("action","A180601.do");
	        throw new GSException(GSException.E20080,GSException.E20080_MSG);
	    }
        
        GSBusOrgProcessor processor = new GSBusOrgProcessor ();
        ArrayList ary = processor.getSubOrgAndInfo(operatorBean.getGs_oper_org_id());
        aForm.getRequest().setAttribute("organdaddr",ary);

        aForm.getRequest().setAttribute("list","TRUE");
        return GSBaseConstants.FORWARD_SUCCESS;
        
	}
	
	   private String[] getPageParams(GSBaseForm aForm,GSOperatorBean operatorBean,GSPayReceiveStatusQueryVO oaqVO) throws Exception{
	       String tStr[] = new String[3];
	       int totalRecords;
	       int pageNo;
	       int pageSize;
	       String tPage = GSBaseConstants.tPage;
	       GSPayReceiveProcessor tProc = new GSPayReceiveProcessor();
	       //根据页面传入的查询参数查询订单信息
	       if(aForm.getRequest().getParameter("choice") == null || aForm.getRequest().getParameter("choice").equals("")){
	       totalRecords = tProc.getPayReceiveStatusListCount(operatorBean,oaqVO);
	           
	           // 取得系统默认的页大小
	           pageSize = Integer.parseInt(tPage);
	           // PageNo=1
	           pageNo = 1;
	           int n = (totalRecords % pageSize == 0 )? totalRecords / pageSize:totalRecords / pageSize + 1;
	           if (pageNo>n) {
	               pageNo=n;
	           }
	           tStr[0] = "" + pageNo;
	           tStr[1] = "" + pageSize;
	           tStr[2] = "" + totalRecords;
	       }else{
	           tStr = GSBaseManager.getPageNoAndPageSize(aForm);
	       }
	       return tStr;
	   }   

}
